package servlet;

import util.DButil;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;

public class Empty extends HttpServlet {
    public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        try{
            DButil dButil = new DButil();
            Connection con = dButil.getConnection();

            String sql = "DELETE from staff ";

            PreparedStatement ps = con.prepareStatement(sql);

            if (ps.executeUpdate() != 0){
                RequestDispatcher dispatcher =
                        request.getRequestDispatcher("index.jsp");//转发
                dispatcher.forward(request, response);
            }
            else
            {
                RequestDispatcher dispatcher=
                        request.getRequestDispatcher("index.jsp");//转发
                dispatcher.forward(request,response);
            }
        }catch(Exception e){
            e.printStackTrace();

        }
        RequestDispatcher dispatcher=
                request.getRequestDispatcher("index.jsp");//转发
        dispatcher.forward(request,response);

    }
    public void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        doGet(request,response);
    }
}
